﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="HMS.PL.Forms.ReEngineering" %>

<% Response.AddHeader("Pragma", "no-cache"); %>
<% Response.AddHeader("Cache-Control", "no-cache"); %>
<% Response.AddHeader("Cache-Control", "no-store"); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Re-Engineering</title>
    <script type="text/javascript" src="../Scripts/jquery-1.6.1.js"></script>
    <link type="text/css" rel="stylesheet" href="../themes/ui-lightness/jquery-ui-1.8.16.custom.css" />
    <link type="text/css" href="../themes/ui-lightness/jquery.ui.all.css" rel="stylesheet" />
    <link type="text/css" rel="stylesheet" href="../Style/!style1.css" />
    <link type="text/css" rel="stylesheet" href="../Style/common.css" />
    <link type="text/css" rel="stylesheet" href="../css/demos.css" />


    <%--jqgrid files--%>
    <link type="text/css" rel="stylesheet" href="../css/ui.jqgrid.css" />
    <link type="text/css" rel="stylesheet" href="../css/ui.multiselect.css" />
    <link type="text/css" rel="stylesheet" href="../themes/redmond/jquery-ui-1.8.1.custom.css" />
    <script src="../Scripts/jquery.layout-latest.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.locale-en.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jqModal.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.base.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.common.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.formedit.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.inlinedit.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.jqueryui.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jquery.contextmenu.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jquery.tablednd.js" type="text/javascript"></script>
    <%-- <script src="../Scripts/jqgrid/grid.formedit.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.inlinedit.js" type="text/javascript"></script>--%>
    <script src="../Scripts/jqgrid/jqDnR.js" type="text/javascript"></script>
    <%--     jquery-ui-1.8.1.custom.css--%>
    <%--jqgrid files--%>
    <script type="text/javascript" src="../Scripts/formsScript/reEngineering.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            ////debugger;
            var reEng = BindComboReEng("drp_table");

            //attribute save button click
            $("#btn_Submit").click(function () {
                Submit();
            });

        });

        function BindComboReEng(comboid) {

            $.ajax({
                async: true,
                type: 'POST',
                url: "ConfigCallback.aspx?operation=bind_reEng",
                success: function (str) {
                    var data = eval('(' + str + ')');
                    //alert($("#" + comboid));
                    $("#" + comboid).empty();
                    var strOptions = "";
                    $.each(data, function (i, elm) {
                        strOptions = strOptions + "<option value=" + elm.Value + ">" + elm.Text + "</option>";
                    });

                    $("#" + comboid).append(strOptions);

                },
                error: function (x, e) {
                    alert('kk');
                    alert(x.readyState + " " + x.status + " " + e.msg);
                }
            });
        }

        function Submit() {
            ////debugger;
            if ($("#drp_table option:selected").val() == "") {
                alert("Please select at least 1 option !");
                return false;
            }
            else {
                //fill grid of columns
                $.ajax({
                    async: true,
                    type: 'GET',
                    url: "ConfigCallback.aspx?operation=get_griddata&table_name=" + $("#drp_table").val() + "&list_name=" + $("#txt_abbr").val(),
                    data: "",
                    dataType: "json",
                    success: function (result) {
                        ////debugger;
                        $("#dataGrid").GridUnload(); // destroy the grid saving the table and pager
                        var editurl = "";
                        //call fill grid for dimension table          
                        fillgridCommon(result, "#dataGrid", "#pager", "800px", "350px", "Table Data", editurl);
                    },
                    error: function (x, e) {
                        ////debugger;
                        alert(x.readyState + " " + x.status + " " + e.msg);
                    }
                });
            }

        }

        function reEngineer() {
            ////debugger;

            if (!$.trim($("#txt_abbr").val())) {
                alert("Please enter the table abbreviation !");
                return false;
            }
            else if ($("#drp_table option:selected").val() == "") {
                alert("Please select at least 1 option !");
                return false;
            }
            else {


                $.ajax({
                    async: true,
                    type: 'POST',
                    url: "ConfigCallback.aspx?operation=ReverseEngConfigTable&list_name=" + $('#txt_abbr').val() + "&table_name=" + $("#drp_table").val(),
                    data: "",
                    dataType: "json",
                    success: function (result) {
                        ////debugger;
                        if (result == true) {
                            alert("Created Successfully !");
                            $("#hid_ret").val('true');
                            //remove created table option
                            //$("select#drp_table option[selected='true']").remove();
                            $('#drp_table :selected').remove();
                        }
                        else if (result == false) {
                            alert("Some  error in creation of table !");
                            return false;
                        }
                        else
                        { alert(result); return false; };

                    },
                    error: function (x, e) {
                        ////debugger;
                        alert(x.readyState + " " + x.status + " " + e.msg);
                    }
                });

            }
        }

        function closeDlg() {
            ////debugger;
            //flag for refresh of exist and un-assgined grid,
            //if we have added relation 
            window.returnValue = $("#hid_ret").val();
            window.close();
        }

    </script>
</head>
<body onbeforeunload="closeDlg();">
    <form id="form1" runat="server">
    <div style="width: 100%">
        <table  class="group_table" cellpadding="0" cellspacing="0" border="0" style="margin:10px">
            <tr>
                <td style="text-align: left;">
                    
                       Select the table</td>
                        <%-- <select style="width: 140px;" id="drp_table" name="drp_table">
                        </select>&nbsp;&nbsp; &nbsp;&nbsp;--%>
                        <td><select style="width: 140px;" id="drp_table" name="drp_table">
                        </select></td>
                        <td><input id="btn_Submit" type="button" value="Submit" class="submit-button" style="height:24px;" />
                   
                </td>
            </tr>
            <tr>
                <td >                
                    Put abbreviation</td>
                    <td colspan="2"><input type="text" name="txt_abbr" id="txt_abbr" style="width: 100px;" />
                    <asp:HiddenField ID="hid_ret" runat="server" Value="false" />
              
                </td>
            </tr>            
        </table>
    </div>
    <div align="center">
        <table id="dataGrid" class="scroll" cellpadding="0" cellspacing="0">
        </table>
        <div id="pager" class="scroll">
        </div>
        <div align="left" style="width: 850px;">
            <input type="button" value="Re-Engineering" onclick="javascript:reEngineer();" class="submit-button"
                style="height: 24px; margin: 5px auto;" />&nbsp;
            <input type="button" value="Cancel" onclick="javascript:closeDlg();" class="submit-button"
                style="height: 24px; margin: 5px auto;" />
        </div>
    </div>
    <div align="right" style="width: 800px;">
        <%-- <input type="button" id="CSubmit_Show" style="height: 24px; margin: 5px auto;" value="Show"
            class="submit-button">&nbsp;<br>--%>
        <%--  <input type="button" value="Re-Engineering" onclick="javascript:reEngineer();" class="submit-button"
            style="height: 24px; margin: 5px auto;" />&nbsp;
        <input type="button" value="Cancel" onclick="javascript:closeDlg();" class="submit-button"
            style="height: 24px; margin: 5px auto;" />--%>
    </div>
    </form>
</body>
</html>
